<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="taskExpressionSqlParamFormQueryRef" :model="taskExpressionSqlParamFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!taskExpressionSqlParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="taskExpressionSqlParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskExpressionSqlParamFormQuerySubmitting" @search="taskExpressionSqlParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="taskExpressionSqlParamFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="taskExpressionSqlParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="taskExpressionSqlParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskExpressionSqlParamFormQuerySubmitting" @search="taskExpressionSqlParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数名">
              <a-input v-model:value="taskExpressionSqlParamFormQueryModel.paramNameAndLike" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数值">
              <a-input v-model:value="taskExpressionSqlParamFormQueryModel.paramValueAndLike" placeholder="输入参数值" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="taskExpressionSqlParamFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="公式参数Id">
              <a-input v-model:value="taskExpressionSqlParamFormQueryModel.expressionParamIdAndLike" placeholder="输入公式参数Id" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="外键Id">
              <a-input v-model:value="taskExpressionSqlParamFormQueryModel.fkidAndLike" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskExpressionSqlParamFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="taskExpressionSqlParamFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="taskExpressionSqlParamFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="taskExpressionSqlParamFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="taskExpressionSqlParamAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="taskExpressionSqlParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskExpressionSqlParamUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="taskExpressionSqlParamListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="taskExpressionSqlParamDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="taskExpressionSqlParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="taskExpressionSqlParamDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="taskExpressionSqlParamTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="taskExpressionSqlParamDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="taskExpressionSqlParamDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="taskExpressionSqlParamListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="taskExpressionSqlParamListColumns"
        :data-source="taskExpressionSqlParamListDataSet"
        :loading="taskExpressionSqlParamListLoading"
        :pagination="false"
        bordered
        :customRow="taskExpressionSqlParamListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: taskExpressionSqlParamListSelectedRowKeys, onChange: taskExpressionSqlParamListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="taskExpressionSqlParamListDataPage"
        v-model:pageSize="taskExpressionSqlParamListDataRows"
        :total="taskExpressionSqlParamListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="taskExpressionSqlParamListPaginationChange"
        @showSizeChange="taskExpressionSqlParamListPaginationShowSizeChange"
        v-if="taskExpressionSqlParamListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!taskExpressionSqlParamListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(taskExpressionSqlParamListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="taskExpressionSqlParamEditDrawerVisible"
      title="编辑任务公式sql参数信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="taskExpressionSqlParamEditDrawerOnClose"
    >
      <a-form ref="taskExpressionSqlParamFormRef" :model="taskExpressionSqlParamFormModel" :rules="taskExpressionSqlParamFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="参数名" name="paramName">
              <a-input v-model:value="taskExpressionSqlParamFormModel.paramName" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="参数值" name="paramValue">
              <a-input v-model:value="taskExpressionSqlParamFormModel.paramValue" placeholder="输入参数值" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="taskExpressionSqlParamFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="公式参数Id" name="expressionParamId">
              <a-input v-model:value="taskExpressionSqlParamFormModel.expressionParamId" placeholder="输入公式参数Id" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="外键Id" name="fkid">
              <a-input v-model:value="taskExpressionSqlParamFormModel.fkid" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskExpressionSqlParamFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="taskExpressionSqlParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="taskExpressionSqlParamFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="taskExpressionSqlParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="taskExpressionSqlParamFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionSqlParamDetailDrawerVisible"
      title="任务公式sql参数详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="参数名" :span="1">{{ taskExpressionSqlParamDetailModel.paramName }}</a-descriptions-item>
          <a-descriptions-item label="参数值" :span="1">{{ taskExpressionSqlParamDetailModel.paramValue }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ taskExpressionSqlParamDetailModel.weightOrder }}</a-descriptions-item>
          <a-descriptions-item label="公式参数Id" :span="1">{{ taskExpressionSqlParamDetailModel.expressionParamId }}</a-descriptions-item>
          <a-descriptions-item label="外键Id" :span="1">{{ taskExpressionSqlParamDetailModel.fkid }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskExpressionSqlParamDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionSqlParamDataImportDrawerVisible"
      title="任务公式sql参数数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="taskExpressionSqlParamDataImportFileUploadRef" :fileModule="taskExpressionSqlParamDataImportFileModule" @change="taskExpressionSqlParamDataImportFileUploadChange" />
          <a-input v-model:value="taskExpressionSqlParamDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="taskExpressionSqlParamDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="taskExpressionSqlParamDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="taskExpressionSqlParamToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionSqlParamDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="taskExpressionSqlParamDataImportFileModule" @change="taskExpressionSqlParamDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionSqlParamDataExportDrawerVisible"
      title="任务公式sql参数数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="taskExpressionSqlParamOptionalDataExportFieldList" :selectedDataExportFieldList="taskExpressionSqlParamSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="taskExpressionSqlParamToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="taskExpressionSqlParamToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useTaskExpressionSqlParamStore } from '/@/store/modules/cn/core/kpis/taskExpressionSqlParamStore'

import type { TaskExpressionSqlParam } from '/@/model/cn/core/kpis/eo/TaskExpressionSqlParam'
import { toTaskExpressionSqlParam } from '/@/model/cn/core/kpis/eo/TaskExpressionSqlParam'

import type { TaskExpressionSqlParamQO } from '/@/model/cn/core/kpis/qo/TaskExpressionSqlParamQO'
import { toTaskExpressionSqlParamQO } from '/@/model/cn/core/kpis/qo/TaskExpressionSqlParamQO'

import type { TaskExpressionSqlParamVO } from '/@/model/cn/core/kpis/vo/TaskExpressionSqlParamVO'
import { toTaskExpressionSqlParamVO } from '/@/model/cn/core/kpis/vo/TaskExpressionSqlParamVO'

@Options({
  name: 'TaskExpressionSqlParam',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useTaskExpressionSqlParamStore),
  },
})
export default class TaskExpressionSqlParam extends Vue {

  taskExpressionSqlParamListDataSet: Array<TaskExpressionSqlParamVO> = []

  taskExpressionSqlParamListColumns: Array<object> = [
    {
      title: '参数名',
      dataIndex: 'paramName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '参数值',
      dataIndex: 'paramValue',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '公式参数Id',
      dataIndex: 'expressionParamId',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '外键Id',
      dataIndex: 'fkid',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  taskExpressionSqlParamListLoading: boolean = false

  taskExpressionSqlParamListSelectedRowKeys: string[] = []

  taskExpressionSqlParamListSelectData: Array<TaskExpressionSqlParamVO> = []

  taskExpressionSqlParamListSelectLength: number = 0

  taskExpressionSqlParamListSelectCurrentRowIndex: number = -1

  taskExpressionSqlParamListSelectCurrentRowData: TaskExpressionSqlParamVO = toTaskExpressionSqlParamVO()

  taskExpressionSqlParamListPaginationVisible: boolean = true

  taskExpressionSqlParamListDataPage: number = 1

  taskExpressionSqlParamListDataRows: number = 10

  taskExpressionSqlParamListDataCount: number = 0

  taskExpressionSqlParamListRowClickTimeout: number | null = null

  taskExpressionSqlParamListRowOnChange(selectedRowKeys, selectedRows) {
    this.taskExpressionSqlParamListSelectedRowKeys = [ ...selectedRowKeys ]
    this.taskExpressionSqlParamListSelectData = [ ...selectedRows ]
    this.taskExpressionSqlParamListSelectLength = selectedRows.length
  }

  taskExpressionSqlParamListCustomRow(record, index) {
    return {
      'class': index === this.taskExpressionSqlParamListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.taskExpressionSqlParamListRowClickTimeout) {
          clearTimeout(this.taskExpressionSqlParamListRowClickTimeout)
          this.taskExpressionSqlParamListRowClickTimeout = null
        } else {
          this.taskExpressionSqlParamListRowClickTimeout = setTimeout(() => {
            this.taskExpressionSqlParamListRowClickTimeout = null
            this.taskExpressionSqlParamListSelectCurrentRowIndex = index
            this.taskExpressionSqlParamListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.taskExpressionSqlParamListSelectedRowKeys ]
            let selectedRows = [ ...this.taskExpressionSqlParamListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.taskExpressionSqlParamListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.taskExpressionSqlParamListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.taskExpressionSqlParamStore.pkVo(this.$toParam<TaskExpressionSqlParamQO>({ id: record.id } as TaskExpressionSqlParamQO)).then((res: Res<TaskExpressionSqlParamVO>) => {
          if (res.succ) {
            this.taskExpressionSqlParamDetailModel = { ...res.data[0] }
            this.taskExpressionSqlParamDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  taskExpressionSqlParamListGetDataSet() {
    this.taskExpressionSqlParamListLoading = true
    this.taskExpressionSqlParamListRowOnChange([], [])
    this.taskExpressionSqlParamListSelectCurrentRowIndex = -1
    this.taskExpressionSqlParamListSelectCurrentRowData = toTaskExpressionSqlParamVO()
    this.taskExpressionSqlParamStore.pagingVo(this.$toParam<TaskExpressionSqlParamQO>({ weightOrderAsc: 'y' } as TaskExpressionSqlParamQO, this.taskExpressionSqlParamListDataPage, this.taskExpressionSqlParamListDataRows)).then((res: Res<TaskExpressionSqlParamVO>) => {
      if (res.succ) {
        this.taskExpressionSqlParamListPaginationVisible = true
        this.taskExpressionSqlParamListDataSet = [ ...res.data ]
        this.taskExpressionSqlParamListDataCount = res.count
        setTimeout(() => { this.taskExpressionSqlParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionSqlParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionSqlParamListLoading = false }, 500)
    })
  }

  taskExpressionSqlParamListPaginationChange() {
    this.taskExpressionSqlParamListGetDataSet()
  }

  taskExpressionSqlParamListPaginationShowSizeChange() {
    this.taskExpressionSqlParamListGetDataSet()
  }

  taskExpressionSqlParamFormQueryVisible: boolean = false

  taskExpressionSqlParamFormQuerySubmitting: boolean = false

  taskExpressionSqlParamFormQueryModel: TaskExpressionSqlParamQO = toTaskExpressionSqlParamQO()

  taskExpressionSqlParamFormQueryUpDown() {
    this.taskExpressionSqlParamFormQueryVisible = !this.taskExpressionSqlParamFormQueryVisible
  }

  taskExpressionSqlParamFormQueryReset() {
    if (this.$refs.taskExpressionSqlParamFormQueryRef) {
      this.$refs.taskExpressionSqlParamFormQueryRef.resetFields()
      this.taskExpressionSqlParamFormQueryModel = toTaskExpressionSqlParamQO()
    }
  }

  taskExpressionSqlParamFormQuerySearch() {
    this.taskExpressionSqlParamFormQuerySubmitting = true
    this.taskExpressionSqlParamListLoading = true
    this.taskExpressionSqlParamListRowOnChange([], [])
    this.taskExpressionSqlParamListSelectCurrentRowIndex = -1
    this.taskExpressionSqlParamListSelectCurrentRowData = toTaskExpressionSqlParamVO()
    this.taskExpressionSqlParamStore.queryVo(this.$toParam<TaskExpressionSqlParamQO>(this.$toSearch({ ...this.taskExpressionSqlParamFormQueryModel }))).then((res: Res<TaskExpressionSqlParamVO>) => {
      if (res.succ) {
        this.taskExpressionSqlParamListPaginationVisible = false
        this.taskExpressionSqlParamListDataSet = [ ...res.data ]
        this.taskExpressionSqlParamListDataCount = res.count
        setTimeout(() => { this.taskExpressionSqlParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskExpressionSqlParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionSqlParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskExpressionSqlParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionSqlParamFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.taskExpressionSqlParamListLoading = false }, 500)
    })
  }

  taskExpressionSqlParamEditDrawerVisible: boolean = false

  taskExpressionSqlParamFormSaveSubmitting: boolean = false

  taskExpressionSqlParamFormSaveContinue: boolean = false

  taskExpressionSqlParamFormModel: TaskExpressionSqlParam = toTaskExpressionSqlParam()

  taskExpressionSqlParamFormRules: object = {
    // paramName: [
    //   { type: 'string', required: true, message: '参数名不能为空！', trigger: ['change', 'blur'] },
    // ],
    // paramValue: [
    //   { type: 'string', required: true, message: '参数值不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
    // expressionParamId: [
    //   { type: 'string', required: true, message: '公式参数Id不能为空！', trigger: ['change', 'blur'] },
    // ],
    // fkid: [
    //   { type: 'string', required: true, message: '外键Id不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  taskExpressionSqlParamFormReset() {
    if (this.$refs.taskExpressionSqlParamFormRef) {
      this.$refs.taskExpressionSqlParamFormRef.resetFields()
      this.taskExpressionSqlParamFormModel = toTaskExpressionSqlParam()
    }
  }

  taskExpressionSqlParamFormSubmit() {
    this.taskExpressionSqlParamFormSaveSubmitting = true
    this.$refs.taskExpressionSqlParamFormRef.validate().then(() => {
      if (this.taskExpressionSqlParamFormModel.id) {
        this.taskExpressionSqlParamStore.update(this.$toParam<TaskExpressionSqlParam>(this.taskExpressionSqlParamFormModel)).then((res: Res<TaskExpressionSqlParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskExpressionSqlParamFormReset()
            this.taskExpressionSqlParamFormSaveSubmitting = false
            if (!this.taskExpressionSqlParamFormSaveContinue) {
              this.taskExpressionSqlParamEditDrawerVisible = false
              this.taskExpressionSqlParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskExpressionSqlParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskExpressionSqlParamFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.taskExpressionSqlParamStore.save(this.$toParam<TaskExpressionSqlParam>(this.taskExpressionSqlParamFormModel)).then((res: Res<TaskExpressionSqlParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskExpressionSqlParamFormReset()
            this.taskExpressionSqlParamFormSaveSubmitting = false
            if (!this.taskExpressionSqlParamFormSaveContinue) {
              this.taskExpressionSqlParamEditDrawerVisible = false
              this.taskExpressionSqlParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskExpressionSqlParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskExpressionSqlParamFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.taskExpressionSqlParamFormSaveSubmitting = false }, 3000)
    })
  }

  taskExpressionSqlParamFormSave() {
    this.taskExpressionSqlParamFormSaveContinue = false
    this.taskExpressionSqlParamFormSubmit()
  }

  taskExpressionSqlParamFormNextAdd() {
    this.taskExpressionSqlParamFormSaveContinue = true
    this.taskExpressionSqlParamFormSubmit()
  }

  taskExpressionSqlParamAdd() {
    if (this.taskExpressionSqlParamFormModel.id) {
      this.taskExpressionSqlParamFormReset()
    }
    this.taskExpressionSqlParamEditDrawerVisible = true
  }

  taskExpressionSqlParamUpdate() {
    this.taskExpressionSqlParamStore.pk(this.$toParam<TaskExpressionSqlParamQO>({ id: this.taskExpressionSqlParamListSelectData[0].id } as TaskExpressionSqlParamQO)).then((res: Res<TaskExpressionSqlParam>) => {
      if (res.succ) {
        this.taskExpressionSqlParamFormReset()
        this.taskExpressionSqlParamFormModel = { ...res.data[0] }
        this.taskExpressionSqlParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionSqlParamEditDrawerOnClose() {
    if (this.taskExpressionSqlParamFormSaveContinue) {
      this.taskExpressionSqlParamFormSaveContinue = false
      this.taskExpressionSqlParamListGetDataSet()
    }
  }

  taskExpressionSqlParamDelete() {
    let param: Array<TaskExpressionSqlParam> = []
    this.taskExpressionSqlParamListSelectData.forEach((eo: TaskExpressionSqlParamVO) => {
      param.push({ id: eo.id } as TaskExpressionSqlParam)
    })
    this.taskExpressionSqlParamStore.removeBatch(this.$toParam<TaskExpressionSqlParam>(param)).then((res: Res<TaskExpressionSqlParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.taskExpressionSqlParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionSqlParamDetailDrawerVisible: boolean = false

  taskExpressionSqlParamDetailModel: TaskExpressionSqlParamVO = toTaskExpressionSqlParamVO()

  taskExpressionSqlParamDetailInfo() {
    this.taskExpressionSqlParamStore.pkVo(this.$toParam<TaskExpressionSqlParamQO>({ id: this.taskExpressionSqlParamListSelectData[0].id } as TaskExpressionSqlParamQO)).then((res: Res<TaskExpressionSqlParamVO>) => {
      if (res.succ) {
        this.taskExpressionSqlParamDetailModel = { ...res.data[0] }
        this.taskExpressionSqlParamDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionSqlParamDetailUpdate() {
    this.taskExpressionSqlParamStore.pk(this.$toParam<TaskExpressionSqlParamQO>({ id: this.taskExpressionSqlParamDetailModel.id } as TaskExpressionSqlParamQO)).then((res: Res<TaskExpressionSqlParam>) => {
      if (res.succ) {
        this.taskExpressionSqlParamFormReset()
        this.taskExpressionSqlParamFormModel = { ...res.data[0] }
        this.taskExpressionSqlParamDetailDrawerVisible = false
        this.taskExpressionSqlParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionSqlParamTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  taskExpressionSqlParamDataImportDrawerVisible: boolean = false

  taskExpressionSqlParamDataImportFileSelectDrawerVisible: boolean = false

  taskExpressionSqlParamDataImportFileModule: string = 'dataImport'

  taskExpressionSqlParamDataImportFileUrl: string = ''

  taskExpressionSqlParamDataImportSaveSubmitting: boolean = false

  taskExpressionSqlParamDataImport() {
    this.taskExpressionSqlParamDataImportDrawerVisible = true
  }

  taskExpressionSqlParamDataImportFileUploadChange(value) {
    this.taskExpressionSqlParamDataImportFileUrl = value
  }

  taskExpressionSqlParamDataImportFileUrlSelectFileClick() {
    this.taskExpressionSqlParamDataImportFileSelectDrawerVisible = true
  }

  taskExpressionSqlParamDataImportFileSelectChange(fileUrl) {
    this.taskExpressionSqlParamDataImportFileUrl = fileUrl
    this.taskExpressionSqlParamDataImportFileSelectDrawerVisible = false
  }

  taskExpressionSqlParamToDataImport() {
    this.taskExpressionSqlParamDataImportSaveSubmitting = true
    this.taskExpressionSqlParamStore.dataImport(this.$toParam<string>(this.taskExpressionSqlParamDataImportFileUrl)).then((res: Res<TaskExpressionSqlParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.taskExpressionSqlParamDataImportFileUploadRef.resetFiles()
        this.taskExpressionSqlParamDataImportFileUrl = ''
        this.taskExpressionSqlParamDataImportSaveSubmitting = false
        this.taskExpressionSqlParamDataImportDrawerVisible = false
        this.taskExpressionSqlParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionSqlParamDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionSqlParamDataImportSaveSubmitting = false }, 3000)
    })
  }

  taskExpressionSqlParamDataExportDrawerVisible: boolean = false

  taskExpressionSqlParamOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'paramName',
      fieldComment: '参数名',
    },
    {
      fieldName: 'paramValue',
      fieldComment: '参数值',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
    {
      fieldName: 'expressionParamId',
      fieldComment: '公式参数Id',
    },
    {
      fieldName: 'fkid',
      fieldComment: '外键Id',
    },
  ]

  taskExpressionSqlParamSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  taskExpressionSqlParamDataExport() {
    this.taskExpressionSqlParamDataExportDrawerVisible = true
  }

  taskExpressionSqlParamToDataExport(allData: boolean) {
    this.taskExpressionSqlParamStore.dataExport(this.$toParam<DataExportAO<TaskExpressionSqlParamQO>>(toDataExportAO(this.taskExpressionSqlParamSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as TaskExpressionSqlParamQO : this.$toSearch({ ...this.taskExpressionSqlParamFormQueryModel }), '任务公式sql参数信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    // this.taskExpressionSqlParamFormQueryModel.weightOrderAsc = 'y'
    this.taskExpressionSqlParamListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
